<template>
  <div class="goods-relevant">
    <div class="goods-header">
      <i class="icon"></i>
      <span class="title">{{ goodsId ? '商品同类推荐' : '猜你喜欢' }}</span>
    </div>
    <RbtCarousel :sliders="sliders" auto-play />
  </div>
</template>

<script setup lang="ts">
import { findRelGoods } from '@/api/product'
import { CateGoryGoods } from '@/types/category'
const props = defineProps({
  goodsId: {
    type: String,
    default: undefined
  }
})

const sliders = ref<CateGoryGoods[][]>([])
const useRelGoodsData = () => {
  findRelGoods(props.goodsId).then(res => {
    // 每页4条
    const size = 4
    const total = Math.ceil(res.data.result.length / size)
    for (let i = 0; i < total; i++) {
      sliders.value.push(res.data.result.slice(i * size, (i + 1) * size))
    }
    console.log(sliders.value)
  })
}

onMounted(() => {
  useRelGoodsData()
})
</script>

<style scoped lang="scss">
.goods-relevant {
  background: #fff;
  min-height: 460px;
  margin-top: 20px;
  .goods-header {
    height: 80px;
    line-height: 80px;
    padding: 0 20px;
    .title {
      font-size: 20px;
      padding-left: 10px;
    }
    .icon {
      width: 16px;
      height: 16px;
      display: inline-block;
      border-top: 4px solid $rbtColor;
      border-right: 4px solid $rbtColor;
      box-sizing: border-box;
      position: relative;
      transform: rotate(45deg);
      &::before {
        content: '';
        width: 10px;
        height: 10px;
        position: absolute;
        left: 0;
        top: 2px;
        background: lighten($color: $rbtColor, $amount: 40%);
      }
    }
  }
  :deep(.rbt-carousel) {
    height: 380px;
    .carousel {
      &-indicator {
        bottom: 30px;
        span {
          &.active {
            background: $rbtColor;
          }
        }
      }
      &-btn {
        top: 110px;
        opacity: 1;
        background: rgba(0, 0, 0, 0);
        color: #ddd;
        i {
          font-size: 30px;
        }
      }
    }
  }
}
</style>
